//index.js
//获取应用实例
const app = getApp();

Page({
  data: {
    motto: "Hello World",
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse("button.open-type.getUserInfo"),
    hide_home: false,
    hide_personal: true,
    ranges: [
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140015417.jpg",
        name: "航天",
        link: "www.baidu.com"
      },
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140018716.jpg",
        name: "李四",
        link: "www.baidu.com"
      },
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140020943.jpg",
        name: "王五",
        link: "www.baidu.com"
      },
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140022797.jpg",
        name: "赵柳",
        link: "www.baidu.com"
      },
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140024903.jpg",
        name: "孙琦",
        link: "www.baidu.com"
      },
      {
        src: "http://img.sj33.cn/uploads/allimg/200905/20090520140027978.jpg",
        name: "周正",
        link: "www.baidu.com"
      }
    ],
    list: [
      {
        src:
          "http://b.hiphotos.baidu.com/image/pic/item/f3d3572c11dfa9ec53b720856fd0f703908fc183.jpg",
        intro: "反馈时间电话开始的刚开始三等奖各环节十多个",
        link: "www.baidu.com",
        qrUrl:'http://b.hiphotos.baidu.com/image/pic/item/f3d3572c11dfa9ec53b720856fd0f703908fc183.jpg',
      },
      {
        src:
          "http://a.hiphotos.baidu.com/image/h%3D300/sign=85c0e0a9e8dde711f8d245f697eecef4/71cf3bc79f3df8dc81a2df3dc011728b461028fa.jpg",
        intro: "反馈时间电话开始的刚开始三等奖各环节十多个",
        link: "www.baidu.com",
        qrUrl:'http://a.hiphotos.baidu.com/image/h%3D300/sign=85c0e0a9e8dde711f8d245f697eecef4/71cf3bc79f3df8dc81a2df3dc011728b461028fa.jpg'
      }
    ],
    texts:"欢迎来到公众号之家，我们将为您提供最优质的公众号聚合服务"
  },
  
  onLoad: function() {
    this.setData("active", 1);
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      });
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        });
      };
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo;
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          });
        }
      });
    }
  },
  getUserInfo: function(e) {
    console.log(e);
    app.globalData.userInfo = e.detail.userInfo;
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    });
  },
  onChange: function(e) {
    var toIndex = e.detail;
    if (toIndex == 1) {
      this.setData({
        hide_personal: false,
        hide_home: true
      });
    } else {
      this.setData({
        hide_personal: true,
        hide_home: false
      });
    }
  },
  toSub: function(e) {
    wx.navigateTo({
      url: e.target.dataset.url
    });
  }
});
